//
//  YSHUDManagerViewController.m
//  YSKitDemo
//
//  Created by Kyson on 2018/10/11.
//  Copyright © 2018 YangShen. All rights reserved.
//

#import "YSHUDManagerViewController.h"
#import "MBProgressHUD+YSHUDManager.h"

@interface YSHUDManagerViewController () <UITableViewDelegate,UITableViewDataSource>
{
    NSArray *titles;
    NSArray *data;
}

@end

@implementation YSHUDManagerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    titles = @[@"菊花",
               @"文字+提示",
               @"图片/动画",
               ];
    
    data = @[
             @[@"菊花-一直存在  --  window",
               @"菊花-3s消失  --  self.view",
               @"菊花+文字-3s消失",
               @"菊花+文字+详情-3s消失 -- self.navigationController.view",
               @"菊花+文字+详情-3s消失 -- 自定义"
               ],
             
             @[@"默认: 中间显示 - 1.2s消失",
               @"顶部显示-3s消失",
               @"底部显示详情-3s消失"],
             @[@"成功",
               @"失败+提示",
               @"图片数组 - 默认大小",
               @"图片数组 - 指定大小",
               @"图片数组+提示 - 指定大小",
               @"GIF",
               @"GIF+提示"],
             ];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"测试" style:UIBarButtonItemStylePlain target:self action:@selector(testClick)];
    self.navigationItem.rightBarButtonItem = item;
}

- (void)testClick {
    NSLog(@"点击 navigationItem 按钮");
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return titles.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [data[section] count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return titles[section];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *rid = @"cellID";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:rid];
    if(cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault      reuseIdentifier:rid];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.textLabel.text = data[indexPath.section][indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        
        switch (indexPath.row) {
            case 0: {
                [MBProgressHUD showInView:self.view];
            }
                break;
            case 1: {
                [MBProgressHUD showInView:self.view afterDelay:3];
            }
                break;
            case 2: {
                [MBProgressHUD showWithTitle:@"我是标题" detail:nil afterDelay:3];
            }
                break;
            case 3: {
                [MBProgressHUD showWithTitle:@"我是标题" detail:@"我是详情" inView:self.view];
            }
                break;
            case 4: {
                [MBProgressHUD showWithTitle:@"我是标题" detail:@"我是详情" inView:nil afterDelay:5 configHUD:^(MBProgressHUD *hud) {
                    hud.contentColor = [UIColor yellowColor];
                    hud.titleColor(UIColor.redColor);
                    hud.bezelBackgroundColor(UIColor.greenColor);
                    hud.hudBackgroundColor([[UIColor blueColor] colorWithAlphaComponent:0.2]);
                }];
            }
                break;
            default:
                break;
        }
        
    } else if (indexPath.section == 1) {
        
        switch (indexPath.row) {
            case 0: {
                [MBProgressHUD showTip:@"我是消息"];
            }
                break;
            case 1: {
                [MBProgressHUD showTip:@"我是消息啊 啊 啊  你好妈的垃圾达拉斯爱神的箭阿了解到家肯德基垃圾杀了健康的" position:YSHUDPositionTop afterDelay:3];
            }
                break;
            case 2: {
                [MBProgressHUD showTip:@"我是消息" detail:@"我是想去萨克达删掉了捡垃圾上课了大剂量的家里会计师的垃圾垃圾死得啦" position:YSHUDPositionBottom afterDelay:3];
            }
                break;
            default:
                break;
        }
    } else if (indexPath.section == 2) {
        
        switch (indexPath.row) {
            case 0: {
                [MBProgressHUD showImage:[UIImage imageNamed:@"right"] message:nil afterDelay:3];
            }
                break;
            case 1: {
                [MBProgressHUD showImage:[UIImage imageNamed:@"error"] message:@"失败了，请重试！" afterDelay:3];
            }
                break;
            case 2: {
                NSMutableArray *array = [NSMutableArray array];
                for (NSInteger i = 1; i <= 8; i++) {
                    [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"show_loading%zd",i]]];
                }
                [MBProgressHUD showImages:array message:nil afterDelay:3];
            }
                break;
            case 3: {
                NSMutableArray *array = [NSMutableArray array];
                for (NSInteger i = 1; i <= 8; i++) {
                    [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"show_loading%zd",i]]];
                }
                [MBProgressHUD showImages:array showSize:CGSizeMake(40, 40) message:nil afterDelay:3];
            }
                break;
            case 4: {
                NSMutableArray *array = [NSMutableArray array];
                for (NSInteger i = 1; i <= 8; i++) {
                    [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"show_loading%zd",i]]];
                }
                [MBProgressHUD showImages:array showSize:CGSizeMake(40, 40) message:@"我是动画" afterDelay:3];
            }
                break;
            case 5: {
                UIImage *giftImage = [MBProgressHUD imageGIFWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"loading@2x" ofType:@"gif"]]];
                [MBProgressHUD showGif:giftImage message:nil afterDelay:3];
            }
                break;
            case 6: {
                UIImage *giftImage = [MBProgressHUD imageGIFWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"loading@2x" ofType:@"gif"]]];
                [MBProgressHUD showGif:giftImage message:@"提示提示提示" afterDelay:3];
            }
                break;
            default:
                break;
        }        
    }
}

@end
